const tokens = []
let templateString = ''
let start = 0
let end = 0
export default function (templateStr) {
    templateString = templateStr.trim()
    while (end < templateString.length - 2) {
        const text = scaner('{{')
        text && tokens.push(['text', text])
        const name = scaner('}}')
        name && tokens.push(['name', name])
    }
    return tokens
}

function scan(token) {
    start = end = end + token.length
}

function scaner(endToken) {
    const index = templateString.slice(end).indexOf(endToken)
    let res = ''
    if (index !== -1) {
        end += index
        res = templateString.slice(start, end)
        scan(endToken)
    } else {
        res = templateString.slice(end)
        end = templateString.length
    }
    return res
}